import { sjexp } from "./App"
export async function information() {
    setInterval(() => {
        world.querySelectorAll("player").forEach((e)=>{
            var needexp=String(sjexp(e.level))
            remoteChannel.sendClientEvent(e, {
                type: "information",
                data: {
                    position: {
                        x:(e.position.x).toFixed(0),
                        y:(e.position.y).toFixed(0),
                        z:(e.position.z).toFixed(0),
                    },
                    exp: e.exp,
                    sjexp: needexp,
                    level: e.level,
                }
            })
        })
    }, 200)
}

/**
 * 添加物品时ui显示
 * @param text 物品名称
 * @param entity 添加物品的实体
 */
export function add_uiShow(text: string,entity:GamePlayerEntity){
    remoteChannel.sendClientEvent(entity, {
        type: 'add',
        data: {
            text: text,
        }
    })
}
export function uiHp() {
    setInterval(() => {
        world.querySelectorAll("player").forEach((e)=>{
            remoteChannel.sendClientEvent(e, {
                type: "hp",
                data: {
                    hp:e.hp,
                    maxHp:e.maxHp,
                }
            })
        })
    }, 100)
}

/**
 * 为玩家实体发送特效文本
 * @param text 特效文本
 * @param entity 目标实体
 */
export function qpTx(text: string, entity: GamePlayerEntity) {
    remoteChannel.sendClientEvent(entity, {
        type: 'qpTx',
        data: {
            text: text,
        }
    })
}